import scrollIntoView from 'scroll-into-view-if-needed';

export const scrollToField = (errorInfo: any) => {
  const fieldKey = errorInfo.errorFields[0].name[0];

  const labelNode = document.querySelector(`#${fieldKey}`);

  if (labelNode) {
    scrollIntoView(labelNode, {
      behavior: 'smooth',
      scrollMode: 'always',
      block: 'center',
      // inline: 'nearest',
    });
  }
};
